package com.eastfair.builder.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eastfair.boot.request.PageParams;
import com.eastfair.core.base.R;
import com.eastfair.core.exception.BizException;
import com.eastfair.venuebooking.api.ViolationRecordFeign;
import com.eastfair.venueservice.dto.ViolationRecordDTO;
import com.eastfair.venueservice.enumeration.ViolationRecordViolationSourceEnum;
import com.eastfair.venueservice.vo.ViolationRecordVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 搭建商现场违规 REST API.
 *
 * @author dqq
 * @date 2022 /12/6
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/builderViolationRecord")
@Api(value = "BuilderViolationRecordController", tags = "搭建商现场违规")
public class BuilderViolationRecordController {

    @Resource
    private ViolationRecordFeign violationRecordFeign;

    /**
     * 查询违规惩罚记录列表分页
     *
     * @param params the params
     * @return r
     */
    @ApiOperation(value = "查询违规惩罚记录列表分页")
    @PostMapping(value = "/queryViolationRecordList")
    public R<Page<ViolationRecordVO>> queryViolationRecordList(@RequestBody PageParams<ViolationRecordDTO> params) {
        log.info("queryViolationRecordList - 查询违规惩罚记录列表分页, param={}", params);
        try {
            ViolationRecordDTO model = params.getModel();
            model.setViolationSource(ViolationRecordViolationSourceEnum.HOME_CHECK);
            return violationRecordFeign.queryViolationRecordList(params);
        } catch (BizException biz) {
            return R.fail(biz);
        }
    }

    /**
     * 查询违规惩罚记录详情
     *
     * @param violationRecordDTO the violation record dto
     * @return r
     */
    @ApiOperation(value = "查询违规惩罚记录详情")
    @PostMapping(value = "/queryViolationRecordInfo")
    public R<ViolationRecordVO> getViolationRecord(@RequestBody ViolationRecordDTO violationRecordDTO) {
        log.info("queryViolationRecordInfo - 查询违规惩罚记录详情, param={}", violationRecordDTO);
        try {
            return violationRecordFeign.getViolationRecord(violationRecordDTO);
        } catch (BizException biz) {
            return R.fail(biz);
        }
    }
}